package com.itchu.customer;

import com.itchu.system.domain.Song;
import com.itchu.system.domain.SongList;
import com.itchu.system.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/api/collect")
public class vCollectionController {

    @Autowired
    private CollectService collectService;
    /**
     * 用户收藏
     * @param userId   用户id
     * @param sid
     * @param lid
     * @return
     */
    @PostMapping("/save")
    public ResponseEntity<Void> userCollect(
            @RequestParam("userId") Long userId,
            @RequestParam("sid") Long sid,
            @RequestParam("lid") Long lid
    ) {
        collectService.userCollect(userId,sid,lid);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    @PostMapping("/cancelcollect")
    public ResponseEntity<Void> cancelCollect(
            @RequestParam("userId") Long userId,
            @RequestParam("sid") Long sid,
            @RequestParam("lid") Long lid,
            @RequestParam("type") Integer type
    ) {
        collectService.cancelCollect(userId,sid,lid,type);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    @GetMapping("/iscollect")
    public ResponseEntity<Integer> isCollect(
            @RequestParam("userId") Long userId,
            @RequestParam("id") Long id,
            @RequestParam("type") Integer type
    ) {
        Integer code = collectService.isCollect(userId,id, type);
        return ResponseEntity.ok(code);
    }


    @GetMapping("/collectSongs")
    public ResponseEntity<List<Song>> getCollectSongs(@RequestParam("userId") Long userId) {
        List<Song> songs = collectService.getCollectSongs(userId);

        return ResponseEntity.ok(songs);
    }

    @GetMapping("/collectLists")
    public ResponseEntity<List<SongList>> getCollectLists(@RequestParam("userId") Long userId) {
        List<SongList> lists = collectService.getCollectLists(userId);

        return ResponseEntity.ok(lists);
    }

    @GetMapping("/allCollects")
    public ResponseEntity<Long> getAllCollect() {
        Long count = collectService.getAllCollect();

        return ResponseEntity.ok(count);
    }
}
